package com.quinn.myDemo;
import java.util.Arrays;
import java.util.Random;
import java.util.Arrays;
import java.util.Random;

/**
 * DoubleColorBallGenerator
 *
 * @author HanQuinn
 * Date: 2023/8/14
 * Time: 15:21
 */
public class DoubleColorBallGenerator {
    public static void main(String[] args) {
        int[] redBalls = generateRedBalls();
        int blueBall = generateBlueBall();

        System.out.println("红色球号码：" + Arrays.toString(redBalls));
        System.out.println("蓝色球号码：" + blueBall);
    }

    // 生成红色球号码，范围是1-33，共选取6个不重复的号码
    public static int[] generateRedBalls() {
        int[] redBalls = new int[6];
        Random random = new Random();

        for (int i = 0; i < 6; i++) {
            int ball;
            do {
                ball = random.nextInt(33) + 1;
            } while (contains(redBalls, ball));

            redBalls[i] = ball;
        }

        Arrays.sort(redBalls);
        return redBalls;
    }

    // 生成蓝色球号码，范围是1-16
    public static int generateBlueBall() {
        Random random = new Random();
        return random.nextInt(16) + 1;
    }

    // 判断数组中是否包含某个元素
    public static boolean contains(int[] array, int num) {
        for (int i : array) {
            if (i == num) {
                return true;
            }
        }
        return false;
    }
}

